home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / unix / mp14tar.z / mp14tar / mpack / unixunpk.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  3KB  |  116 lines

  1. /* (C) Copyright 1993 by John G. Myers
  2.  * All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without
  6.  * fee, provided that the above copyright notice appear in all copies
  7.  * and that both that copyright notice and this permission notice
  8.  * appear in supporting documentation, and that the name of John G.
  9.  * Myers not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  John G. Myers makes no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as
  13.  * is" without express or implied warranty.
  14.  *
  15.  * JOHN G. MYERS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL JOHN G. MYERS BE LIABLE FOR ANY SPECIAL,
  18.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  21.  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #include <stdio.h>
  24. #include "version.h"
  25.  
  26. extern int optind;
  27. extern char *optarg;
  28.  
  29. extern int overwrite_files;
  30. extern int didchat;
  31. int quiet;
  32.  
  33. main(argc, argv)
  34. int argc;
  35. char **argv;
  36. {
  37.     int opt;
  38.     FILE *file;
  39.     int extractText = 0;
  40.     
  41.     while ((opt = getopt(argc, argv, "qftC:")) != EOF) {
  42.     switch (opt) {
  43.     case 'f':
  44.         overwrite_files = 1;
  45.         break;
  46.  
  47.     case 'q':
  48.         quiet = 1;
  49.         break;
  50.  
  51.     case 't':
  52.         extractText = 1;
  53.         break;
  54.  
  55.     case 'C':
  56.         if (chdir(optarg)) {
  57.         perror(optarg);
  58.         exit(1);
  59.         }
  60.         break;
  61.  
  62.     default:
  63.         usage();
  64.     }
  65.     }
  66.  
  67.     if (optind == argc) {
  68.     fprintf(stderr, "munpack: reading from standard input\n");
  69.     didchat = 0;
  70.     handleMessage(stdin, "text/plain", 0, extractText, 0);
  71.     if (!didchat) {
  72.         fprintf(stdout,
  73.             "Did not find anything to unpack from standard input\n");
  74.     }
  75.     exit(0);
  76.     }
  77.  
  78.     while (argv[optind]) {
  79.     file = fopen(argv[optind], "r");
  80.     if (!file) {
  81.         perror(argv[optind]);
  82.     }
  83.     else {
  84.         didchat = 0;
  85.         handleMessage(file, "text/plain", 0, extractText, 0);
  86.         fclose(file);
  87.         if (!didchat) {
  88.         fprintf(stdout, 
  89.             "Did not find anything to unpack from %s\n",
  90.             argv[optind]);
  91.         }
  92.     }
  93.     optind++;
  94.     }
  95.     exit(0);
  96. }
  97.  
  98. usage() {
  99.     fprintf(stderr, "munpack version %s\n", MPACK_VERSION);
  100.     fprintf(stderr, "usage: munpack [-f] [-q] [-C directory] [files...]\n");
  101.     exit(1);
  102. }
  103.  
  104. warn(s)
  105. char *s;
  106. {
  107.     fprintf(stderr, "munpack: warning: %s\n", s);
  108. }
  109.  
  110. chat(s)
  111. char *s;
  112. {
  113.     didchat = 1;
  114.     if (!quiet) fprintf(stdout, "%s\n", s);
  115. }
  116.